package com.springboot.controller;


import com.springboot.common.Result;
import com.springboot.entity.UserAddress;
import com.springboot.service.IUserAddressService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 收货地址表 前端控制器
 *
 * @author zjb
 * @since 2025-10-22
 */
@RestController
@RequestMapping("/user-address")
public class UserAddressController {

    @Resource
    private IUserAddressService iUserAddressService;

    /**
     * 添加收货地址
     *
     * @param userAddress 收货地址信息
     * @return 添加结果
     */
    @PostMapping
    public Result addAddress(@RequestBody UserAddress userAddress){
        return iUserAddressService.addAddress(userAddress);
    }

    /**
     * 删除收货地址
     *
     * @param addressId 地址ID
     * @return 删除结果
     */
    @DeleteMapping("/{addressId}")
    public Result removeAddress(@PathVariable Integer addressId){
        return iUserAddressService.removeAddress(addressId);
    }
    
    /**
     * 更新收货地址信息
     *
     * @param addressId   地址ID
     * @param userAddress 收货地址更新信息
     * @return 更新结果
     */
    @PutMapping("/{addressId}")
    public Result updateAddress(@PathVariable Integer addressId,@RequestBody UserAddress userAddress){
        return iUserAddressService.updateAddress(addressId,userAddress);
    }
    
    /**
     * 获取用户收货地址列表
     *
     * @param userId 用户ID
     * @return 地址列表数据
     */
    @GetMapping("/{userId}")
    public Result getAddress(@PathVariable Integer userId){
        return iUserAddressService.getAddress(userId);
    }

}